package com.ctshk.rpc.air.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.air.dto.AreaHasChildrenDTO;
import com.ctshk.rpc.air.dto.SysAreaDTO;
import com.ctshk.rpc.air.entity.SysArea;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-11
 */
public interface SysAreaMapper extends BaseMapper<SysArea> {

    @Select("SELECT a.id,a.status,a.country_code code,a.country_pinyin,a.country_traditional name \n" +
            "FROM t_sys_area a WHERE ( a.is_deleted = #{isDelete} AND a.`level` = #{levelOne} AND a.`level` = #{levelOne}) ")
    List<AreaHasChildrenDTO> getOneLevelArea(
            @Param("isDelete") Integer isDelete,
            @Param("levelOne") Integer levelOne,
            @Param("levelTwo") Integer levelTwo);

    /**
     * 获取国内城市信息
     * @param cn
     * @param xg
     * @param am
     * @param tw
     * @return
     */
    @Select("select '国内' as country_simple,t.id,t.province_simple,t.city_simple \n" +
            "from `ctshk-cloud`.t_sys_area t \n" +
            "where t.country_code = #{cn} or t.country_code = #{xg} or t.country_code = #{am} or t.country_code = #{tw} \n" +
            "and t.province_simple is not null \n" +
            "GROUP BY t.province_simple,t.city_simple  limit 20")
    List<SysAreaDTO> getCountryWithin(
            @Param("cn") String cn,
            @Param("xg") String xg,
            @Param("am") String am,
            @Param("tw") String tw);

    /**
     * 获取国外城市信息
     * @param cn
     * @param xg
     * @param am
     * @param tw
     * @return
     */
    @Select("select '国外' as country_simple,ts.id,ts.province_simple,ts.city_simple\n" +
            "from `ctshk-cloud`.t_sys_area ts \n" +
            "where ts.country_code <> #{cn} and ts.country_code <> #{xg} and ts.country_code <> #{am} and ts.country_code <> #{tw} \n" +
            "and ts.province_simple is not null \n" +
            "GROUP BY ts.province_simple,ts.city_simple  limit 20")
    List<SysAreaDTO> getCountryOutside(
            @Param("cn") String cn,
            @Param("xg") String xg,
            @Param("am") String am,
            @Param("tw") String tw);
}
